import { http, HttpResponse } from 'msw'
import Mock from 'mockjs'
// 角色列表
export const roleList = http.post('/data/ed/role/list', () => {
  let roleList = Mock.mock({
    'list|100': [
      {
        roleId: function () {
          return `role_${Mock.Random.increment()}`
        },
        roleName: '@name',
        roleDesc: '@string',
        dataScope: '@string',
        allowedActions: '@string',
      },
    ],
  })
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: {
      records: roleList.list,
    },
  })
})
// 新增角色
export const addRole = http.post('/data/ed/role/createRole', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: {},
  })
})
//编辑角色
export const editRole = http.post('/data/ed/role/updateRole', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
  })
})
// 查单个角色
export const getRole = http.get('/data/ed/role/getSingleRole/:roleId', () => {
  const tree = [
    {
      id: '1',
      fileName: 'apple',
      dataAuth: {
        data: false,
      },
      permission: {
        view: false,
        edit: false,
        move: false,
        delete: false,
        upload: false,
        download: false,
        import: false,
        export: false,
      },
      children: [
        {
          id: '2',
          fileName: '初步设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
          children: [
            {
              id: '21',
              fileName: 'HIRF',
              dataAuth: {
                data: true,
              },
              permission: {
                view: true,
                edit: true,
                move: true,
                delete: true,
                upload: true,
                download: true,
                import: true,
                export: true,
              },
              children: [
                {
                  id: '211',
                  fileName: 'nnn',
                  dataAuth: {
                    data: true,
                  },
                  permission: {
                    view: true,
                    edit: true,
                    move: true,
                    delete: true,
                    upload: true,
                    download: true,
                    import: true,
                    export: true,
                  },
                },
                {
                  id: '212',
                  fileName: 'jjj',
                  dataAuth: {
                    data: true,
                  },
                  permission: {
                    view: true,
                    edit: true,
                    move: true,
                    delete: true,
                    upload: true,
                    download: true,
                    import: true,
                    export: true,
                  },
                },
              ],
            },
            {
              id: '22',
              fileName: '雷电',
              dataAuth: {
                data: false,
              },
              permission: {
                view: false,
                edit: false,
                move: false,
                delete: false,
                upload: false,
                download: false,
                import: false,
                export: false,
              },
            },
          ],
        },
        {
          id: '3',
          fileName: '立项设计',
          dataAuth: {
            data: true,
          },
          permission: {
            view: true,
            edit: true,
            move: true,
            delete: true,
            upload: true,
            download: true,
            import: true,
            export: true,
          },
        },
      ],
    },
    {
      id: '4',
      fileName: 'orange',
      dataAuth: {
        data: true,
      },
      permission: {
        view: true,
        edit: true,
        move: true,
        delete: true,
        upload: true,
        download: true,
        import: true,
        export: true,
      },
      children: [
        {
          id: '6',
          fileName: '初步设计',
          dataAuth: {
            data: true,
          },
          permission: {
            view: true,
            edit: true,
            move: true,
            delete: true,
            upload: true,
            download: true,
            import: true,
            export: true,
          },
        },
        {
          id: '7',
          fileName: '立项设计',
          dataAuth: {
            data: true,
          },
          permission: {
            view: true,
            edit: true,
            move: true,
            delete: true,
            upload: true,
            download: true,
            import: true,
            export: true,
          },
        },
      ],
    },
    {
      id: '5',
      fileName: 'balana',
      dataAuth: {
        data: false,
      },
      permission: {
        view: false,
        edit: false,
        move: false,
        delete: false,
        upload: false,
        download: false,
        import: false,
        export: false,
      },
      children: [
        {
          id: '8',
          fileName: '初步设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
        },
        {
          id: '9',
          fileName: '立项设计',
          dataAuth: {
            data: true,
          },
          permission: {
            view: true,
            edit: true,
            move: true,
            delete: true,
            upload: true,
            download: true,
            import: true,
            export: true,
          },
        },
      ],
    },
  ]
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: {
      roleName: '工程师',
      roleDesc: '普通工程师',
      data: tree,
    },
  })
})
// 删除角色
export const deleteRole = http.get('/data/ed/role/deleteRole/*', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
  })
})
//人员绑定-列表
export const bindRolesList = http.post('/data/ed/user/bindRole/list', () => {
  let roleList = Mock.mock({
    'list|100': [
      {
        userId: '@string',
        userName: '@name',
        workNumber: '@string',
        mobile: '32314',
        userDept: '@string',
        userTitle: '@string',
        joinTime: '@date(yyyy-MM-dd)',
        gmtCreate: '@date(yyyy-MM-dd HH:mm:ss)',
        'isActivated|0-1': 1,
        'isPublished|0-1': 1,
        'isDefaultPwd|0-1': 1,
        internshipEndDate: '@date(yyyy-MM-dd)',
        userStatus: 'job',
        userAccount: '@string',
        userPwd: '@string',
        roleList: ['C939工程师', 'C919工程师'],
      },
    ],
  })
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: {
      userList: roleList.list,
    },
  })
})
// 获取所有角色名
export const getRoleNames = http.get('/data/ed/role/getRoleNames', () => {
  let options = [
    { value: 'C919工程师', label: 'C919工程师' },
    { value: 'C929工程师', label: 'C929工程师' },
    { value: 'C939工程师', label: 'C939工程师' },
    { value: 'C949工程师', label: 'C949工程师' },
    { value: 'C959工程师', label: 'C959工程师' },
  ]
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: options,
  })
})
// 新增角色
export const bindRoles = http.post('/data/ed/user/bindRoles', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: {},
  })
})
// 人员绑定-通过角色名称查看权限
export const getRoleByName = http.get('/data/ed/role/getRoleByName', () => {
  let tree = [
    {
      id: '1',
      fileName: 'apple',
      dataAuth: {
        data: false,
      },
      permission: {
        view: false,
        edit: false,
        move: false,
        delete: false,
        upload: false,
        download: false,
        import: false,
        export: false,
      },
      children: [
        {
          id: '2',
          fileName: '初步设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
          children: [
            {
              id: '21',
              fileName: 'HIRF',
              dataAuth: {
                data: true,
              },
              permission: {
                view: true,
                edit: true,
                move: true,
                delete: true,
                upload: true,
                download: true,
                import: true,
                export: true,
              },
              children: [
                {
                  id: '211',
                  fileName: 'nnn',
                  dataAuth: {
                    data: true,
                  },
                  permission: {
                    view: true,
                    edit: true,
                    move: true,
                    delete: true,
                    upload: true,
                    download: true,
                    import: true,
                    export: true,
                  },
                },
                {
                  id: '212',
                  fileName: 'jjj',
                  dataAuth: {
                    data: true,
                  },
                  permission: {
                    view: true,
                    edit: true,
                    move: true,
                    delete: true,
                    upload: true,
                    download: true,
                    import: true,
                    export: true,
                  },
                },
              ],
            },
            {
              id: '22',
              fileName: '雷电',
              dataAuth: {
                data: true,
              },
              permission: {
                view: false,
                edit: true,
                move: true,
                delete: true,
                upload: true,
                download: true,
                import: true,
                export: true,
              },
            },
          ],
        },
        {
          id: '3',
          fileName: '立项设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
        },
      ],
    },
    {
      id: '4',
      fileName: 'orange',
      dataAuth: {
        data: false,
      },
      permission: {
        view: false,
        edit: false,
        move: false,
        delete: false,
        upload: false,
        download: false,
        import: false,
        export: false,
      },
      children: [
        {
          id: '6',
          fileName: '初步设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
        },
        {
          id: '7',
          fileName: '立项设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
        },
      ],
    },
    {
      id: '5',
      fileName: 'balana',
      dataAuth: {
        data: true,
      },
      permission: {
        view: true,
        edit: true,
        move: true,
        delete: true,
        upload: true,
        download: true,
        import: true,
        export: true,
      },
      children: [
        {
          id: '8',
          fileName: '初步设计',
          dataAuth: {
            data: true,
          },
          permission: {
            view: true,
            edit: true,
            move: true,
            delete: true,
            upload: true,
            download: true,
            import: true,
            export: true,
          },
        },
        {
          id: '9',
          fileName: '立项设计',
          dataAuth: {
            data: true,
          },
          permission: {
            view: true,
            edit: true,
            move: true,
            delete: true,
            upload: true,
            download: true,
            import: true,
            export: true,
          },
        },
      ],
    },
  ]
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMsg: '',
    data: {
      roleId: '1871482143708831744',
      roleName: 'C919工程师',
      roleDesc: '角色测试数据',
      data: tree,
    },
  })
})
// 人员绑定-通过角色名称查看权限
export const getRoleTemplate = http.get('/data/ed/role/getRoleTemplate', () => {
  let tree = [
    {
      id: '1',
      fileName: 'apple',
      dataAuth: {
        data: false,
      },
      permission: {
        view: false,
        edit: false,
        move: false,
        delete: false,
        upload: false,
        download: false,
        import: false,
        export: false,
      },
      children: [
        {
          id: '2',
          fileName: '初步设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
          children: [
            {
              id: '21',
              fileName: 'HIRF',
              dataAuth: {
                data: false,
              },
              permission: {
                view: false,
                edit: false,
                move: false,
                delete: false,
                upload: false,
                download: false,
                import: false,
                export: false,
              },
              children: [
                {
                  id: '211',
                  fileName: 'nnn',
                  dataAuth: {
                    data: false,
                  },
                  permission: {
                    view: false,
                    edit: false,
                    move: false,
                    delete: false,
                    upload: false,
                    download: false,
                    import: false,
                    export: false,
                  },
                },
                {
                  id: '212',
                  fileName: 'jjj',
                  dataAuth: {
                    data: false,
                  },
                  permission: {
                    view: false,
                    edit: false,
                    move: false,
                    delete: false,
                    upload: false,
                    download: false,
                    import: false,
                    export: false,
                  },
                },
              ],
            },
            {
              id: '22',
              fileName: '雷电',
              dataAuth: {
                data: false,
              },
              permission: {
                view: false,
                edit: false,
                move: false,
                delete: false,
                upload: false,
                download: false,
                import: false,
                export: false,
              },
            },
          ],
        },
        {
          id: '3',
          fileName: '立项设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
        },
      ],
    },
    {
      id: '4',
      fileName: 'orange',
      dataAuth: {
        data: false,
      },
      permission: {
        view: false,
        edit: false,
        move: false,
        delete: false,
        upload: false,
        download: false,
        import: false,
        export: false,
      },
      children: [
        {
          id: '6',
          fileName: '初步设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
        },
        {
          id: '7',
          fileName: '立项设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
        },
      ],
    },
    {
      id: '5',
      fileName: 'balana',
      dataAuth: {
        data: false,
      },
      permission: {
        view: false,
        edit: false,
        move: false,
        delete: false,
        upload: false,
        download: false,
        import: false,
        export: false,
      },
      children: [
        {
          id: '8',
          fileName: '初步设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
        },
        {
          id: '9',
          fileName: '立项设计',
          dataAuth: {
            data: false,
          },
          permission: {
            view: false,
            edit: false,
            move: false,
            delete: false,
            upload: false,
            download: false,
            import: false,
            export: false,
          },
        },
      ],
    },
  ]
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMsg: '',
    data: {
      roleId: '1871482143708831744',
      roleName: 'C919工程师',
      roleDesc: '角色测试数据',
      data: tree,
    },
  })
})
export const downloadFile = http.get('/data/ed/user/getAdminType', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: 'normal',
  })
})
